using System;
using System.Diagnostics.CodeAnalysis;

namespace Pinwheel.LSerialize
{
    public class LSerializeException : Exception
    {
        public LSerializeException(string message)
            : base(message)
        {
        }

        public LSerializeException(string message, Exception innerException)
            : base(message, innerException)
        {
        }
        
        [DoesNotReturn]
        public static void ThrowMessage(string message)
        {
            throw new LSerializeException(message);
        }
        
        [DoesNotReturn]
        public static void ThrowSerializeObjectIsNull(string target)
        {
            throw new LSerializeException($"Serialized {target} is null!");
        }
        
        [DoesNotReturn]
        public static void ThrowRegisterInProviderFailed(Type type, Exception innerException)
        {
            throw new LSerializeException($"{type.FullName} is failed in provider at creating formatter.", innerException);
        }
        
        [DoesNotReturn]
        public static void ThrowNotRegisteredInProvider(Type type)
        {
            throw new LSerializeException($"{type.FullName} is not registered in this provider.");
        }
        
        [DoesNotReturn]
        public static void ThrowContextDepthOutOfRange(int depth, int limit)
        {
            throw new LSerializeException($"Context depth {depth} is out of range, limit is {limit}.");
        }
        
        [DoesNotReturn]
        public static void ThrowReachedDepthLimit(Type type)
        {
            throw new LSerializeException($"Serializing Type '{type}' reached depth limit, maybe detect circular reference.");
        }
    }
}
